<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">民宿信息</li>
        <li id="hotelPhotoLi">民宿照片</li>
        <li id="hotelHomeLi">房间管理</li>
        <li id="checkInInstructionsLi">入住须知</li>
        <li id="playRaidersLi">场所介绍</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form" style="margin-left: 10%" id="infoForm">
                <input name="id" id="id" type="hidden"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">民宿名称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelName" id="hotelName" lay-verify="required"
                               style="width: 250px" placeholder="请输入民宿名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">民宿副标题:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelTitle" id="hotelTitle" lay-verify="required"
                               style="width: 250px" placeholder="请输入民宿副标题" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">民宿别称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelNickName" id="hotelNickName" lay-verify="required"
                               style="width: 150px" placeholder="请输入民宿别称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">民宿类型:</label>
                    <div class="layui-input-inline" style="width: 150px">
                        <select name="hotelType" id="hotelType">
                            <option value="0">民宿</option>
                            <option value="1">酒店</option>
                            <option value="2">农家乐</option>
                        </select>
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">省:</label>
                    <div class="layui-input-inline" style="width: 150px">
                        <select name="provinceCode" id="provinceCode" lay-filter="province" lay-verify="required">
                        </select>
                    </div>
                    <label class="layui-form-label" style="width: 30px">市:</label>
                    <div class="layui-input-inline" style="width: 150px">
                        <select name="cityCode" id="cityCode" lay-filter="city" lay-verify="required">
                        </select>
                    </div>
                    <label class="layui-form-label" style="width: 30px">区:</label>
                    <div class="layui-input-inline" style="width: 150px">
                        <select name="districtCode" id="districtCode">
                        </select>
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">详细地址:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelAddress" id="hotelAddress" lay-verify="required"
                               style="width: 300px" placeholder="请输入民宿详细地址" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">经度:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="longitude" id="longitude"
                               autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">纬度:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="latitude" id="latitude"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">民宿电话:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelTelNo" id="hotelTelNo" lay-verify="required"
                               style="width: 200px" placeholder="请输入民宿电话" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">最低房价价格:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelPrice" id="hotelPrice" lay-verify="required"
                               style="width: 200px" placeholder="请输入最低房价价格" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <label class="layui-form-label">店长号码:</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile" id="mobile" lay-verify="required"
                                   style="width: 200px" placeholder="请输入店长号码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-input-inline" id="resetDiv" style="margin-left: 100px">
                        <div class="layui-input-block">
                            <input type="text" name="password" id="password"
                                   style="width: 200px" placeholder="请输入需要重置的" autocomplete="off" class="layui-input">
                        </div>

                    </div>
                    <button class="layui-btn" id="resetBtn" style="margin-left: 180px" lay-submit lay-filter="resetPwd">
                        重置民宿密码
                    </button>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">酒店设施:</label>
                    <div class="layui-input-block" id="facilityDiv">

                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">营业时间:</label>
                    <div class="layui-input-block">
                        <input type="text" name="openingHours" id="openingHours" lay-verify="required"
                               style="width: 300px" placeholder="请输入门店营业时间 示例:8:00-18:00" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item">
                    <label class="layui-form-label">民宿标签:</label>
                    <div class="layui-input-block">
                        <input type="text" name="hotelTag" id="hotelTag" lay-verify="required"
                               style="width: 300px" placeholder="请输入民宿标签,以逗号分割 示例:杭州,舒适,宽敞,干净 最多4个,超出只取前4个"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <hr class="layui-bg-gray">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">民宿介绍:</label>
                    <div class="layui-input-block">
                        <div id="hotelInfoEditor" class="w-e-text-container">
                        </div>
                    </div>
                </div>
                <br/>
                <br/>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" style="margin-left: 25%;" lay-submit lay-filter="infoSubmit">立即提交
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-tab-item" id="hotelPhotoDiv">
            <input type="text" name="hotelPhotoId" id="hotelPhotoId" type="hidden" class="layui-input">
            <a id="uploadhotelPhoto" class="layui-btn">新增图片</a>
            <hr class="layui-bg-gray">
            <p id="photoList"></p>
        </div>

        <div class="layui-tab-item" id="hotelHomeDiv">
            <form class="layui-form" style="margin-top: 15px">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">房间名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="homeName" id="homeName" autocomplete="off"
                               class="layui-input">
                    </div>
                    <button class="layui-btn" lay-submit lay-filter="searchHomeBtn">查询</button>
                    <button class="layui-btn" lay-submit lay-filter="addHomeBtn">新增房间</button>
                </div>
            </form>
            <table class="layui-table" id="hotelHomeGrid" lay-filter="hotelHomeGrid">
            </table>
        </div>

        <div class="layui-tab-item" id="checkInInstructionsDiv">
            <div id="checkInInstructionsEditor" class="w-e-text-container">
            </div>
            <div class="layui-input-block">
                <button class="layui-btn" style="margin-left: 42%;margin-top:50px" lay-submit
                        lay-filter="checkInSubmit">立即提交
                </button>
            </div>
        </div>

        <div class="layui-tab-item" id="playRaidersDiv">
            <div id="playRaidersEditor" class="w-e-text-container">
            </div>
            <div class="layui-input-block">
                <button class="layui-btn" style="margin-left: 42%;margin-top: 50px" lay-submit
                        lay-filter="playRaidersSubmit">立即提交
                </button>
            </div>
        </div>
    </div>
</div>
</div>
<script th:replace="/common/inc::incJs"></script>
<style type="text/css">
    imgs {
        width: 375px;
        height: 270px;
    }

    .hotelImage-uploader {
        width: 300px;
        overflow: hidden;
    }

    .hotelImage-uploader .image-preview {
        background-color: #eee;
        position: relative;
        width: 150px;
        height: 150px;
        float: left;
    }

    .hotelImage-uploader .image-browse {
        color: #fff;
        cursor: pointer;
        text-align: center;
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 24px;
        line-height: 24px;
        overflow: hidden
    }

    .hotelImage-uploader img {
        width: 375px;
        height: 270px
    }

    .hotelImage-uploader strong {
        position: relative;
        z-index: 2
    }

    .hotelImage-uploader .progress {
        opacity: .5;
        filter: alpha(opacity=50);
        background-color: #000;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 1
    }

    .hotelImage-uploader .progress-bar {
        background-color: #56b02a;
        display: block;
        height: 100%;
        width: 0
    }

    .hotelImage-uploader input {
        font-size: 50px
    }

    .w-e-text-container {
        height: 600px !important; /*!important是重点，因为原div是行内样式设置的高度300px*/
    }
</style>
<script>
    var form = layui.form;
    var stylistTableIns;
    var hotelHomeTabIns;
    var id = getQueryString("id");
    $("#id").val(id);
    setup();
    layui.form.render('select');

    new ClipboardJS('.copybtn');
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#expiryDate', //指定元素
            format: 'yyyy-MM-dd'
        });
    });

    layui.use(['upload', 'element', 'layer'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;

        var uploadInst1 = upload.render({
            elem: '#uploadhotelPhoto'
            , url: '/backend/security/hotelPhoto/updateSynthesisImg' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    if (file.size > 1024 * 1024) {
                        // delete files[index];                     //过大删除指定图片
                        // $('#remove_' + index).remove();   //展示容器移除
                        layer.msg('图片大小不得超过1M', {icon: 2});
                    }
                });
            }
            , done: function (res) {
                $.post("/backend/security/hotelPhoto/add", {
                    hotelId: id,
                    url: "/static/data/images/" + res.body
                }, function (result) {
                    if (result.code < 0) {
                        layer.msg(result.message);
                    } else {
                        layer.msg('新增成功');
                        $("#hotelPhotoId").val(result.body.id);
                        var id = $("#hotelPhotoId").val();
                        if (id > 0) {
                            var html = "<div class=\"hotelImage-uploader\" id=\"" + result.body.id + "\">\n" +
                                "                <div class=\"image-preview\">\n" +
                                "                    <div class=\"image\">\n" +
                                "                        <img src=\"" + result.body.url + "\"  id=\"img\">\n" +
                                "                        <span class=\"image-browse\" onclick=\"deleteHotelPhoto('" + result.body.id + "')\"><strong>删除图片</strong><span\n" +
                                "                                class=\"progress\"><span class=\"progress-bar\"></span></span></span>\n" +
                                "                    </div>\n" +
                                "                </div>\n" +
                                "            </div><br/>";
                            $("#photoList").append(html);
                        }
                    }
                });
            }
            , error: function (res) {

            }
        });
    });

    var E = window.wangEditor;
    var checkInInstructionsEditor = new E("#checkInInstructionsEditor");
    checkInInstructionsEditor.customConfig.pasteFilterStyle = false;
    checkInInstructionsEditor.customConfig.qiniu = true;
    checkInInstructionsEditor.create();

    var playRaidersEditor = new E("#playRaidersEditor");
    playRaidersEditor.customConfig.pasteFilterStyle = false;
    playRaidersEditor.customConfig.qiniu = true;
    playRaidersEditor.create();

    var hotelInfoEditor = new E("#hotelInfoEditor");
    hotelInfoEditor.customConfig.pasteFilterStyle = false;
    hotelInfoEditor.customConfig.qiniu = true;
    hotelInfoEditor.create();


    // 封装 console.log 函数
    function printLog(title, info) {
        window.console && console.log(title, info);
    }

    //选项卡事件监听
    layui.use('element', function () {
        var $ = layui.jquery
            , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    });


    layui.form.on('submit(addHomeBtn)', function () {
        openDialog({
            url: "/backend/security/hotelHome/detail?hotelId=" + $("#id").val(),
            area: ["80%", "95%"],
            tableId: 'hotelHomeGrid'
        });
        return false;
    });

    //门店基础信息提交
    form.on('submit(infoSubmit)', function (data) {
        var basic_equipment = [];
        var general_equipment = [];
        var bathroom_equipment = [];
        var household_equipment = [];
        var service_equipment = [];
        var hotel_facility = {};

        $.each($('.basic_equipment input:checkbox:checked'), function () {
            basic_equipment.push({"name": $(this).attr("title"), "img": $(this).attr("value")});
        });

        $.each($('.general_equipment input:checkbox:checked'), function () {
            general_equipment.push({"name": $(this).attr("title"), "img": $(this).attr("value")});
        });

        $.each($('.bathroom_equipment input:checkbox:checked'), function () {
            bathroom_equipment.push({"name": $(this).attr("title"), "img": $(this).attr("value")});
        });

        $.each($('.household_equipment input:checkbox:checked'), function () {
            household_equipment.push({"name": $(this).attr("title"), "img": $(this).attr("value")});
        });

        $.each($('.service_equipment input:checkbox:checked'), function () {
            service_equipment.push({"name": $(this).attr("title"), "img": $(this).attr("value")});
        });

        hotel_facility.basic = basic_equipment;
        hotel_facility.general = general_equipment;
        hotel_facility.bathroom = bathroom_equipment;
        hotel_facility.household = household_equipment;
        hotel_facility.service = service_equipment;
        data.field.hotelFacility = JSON.stringify(hotel_facility);
        data.field.hotelInfo = hotelInfoEditor.txt.html();
        data.field.cityName = $("#cityCode").find("option:selected").text();
        data.field.hotelTag = $("#hotelTag").val().replace("，", ",");
        if (id != "") {
            $.post('/backend/security/hotel/updateHotelData', data.field, function (res1) {
                if (res1.code < 0) {
                    layer.msg(res1.message);
                } else {
                    layer.msg('操作成功');
                    parent.layui.table.reload("grid");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });
        } else {
            $.post('/backend/security/hotel/addHotelInfo', data.field, function (reslut) {
                if (reslut.code < 0) {
                    layer.msg(reslut.message);
                } else {
                    layer.msg('操作成功');
                    parent.layui.table.reload("grid");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });
        }
        return false;
    });

    form.on('submit(checkInSubmit)', function () {
        $.post('/backend/security/hotel/update', {
            id: id,
            checkInInstructions: checkInInstructionsEditor.txt.html()
        }, function (reslut) {
            if (reslut.code < 0) {
                layer.msg(reslut.message);
            } else {
                layer.msg('保存入住须知成功');
            }
        });
    });

    form.on('submit(playRaidersSubmit)', function (data) {
        $.post('/backend/security/hotel/update', {
            id: id,
            playRaiders: playRaidersEditor.txt.html()
        }, function (reslut) {
            if (reslut.code < 0) {
                layer.msg(reslut.message);
            } else {
                layer.msg('保存游玩攻略成功');
            }
        });
    });

    form.on('submit(resetPwd)', function (data) {
        if ($("#password").val() == "") {
            layer.msg('请输入需要重置后密码');
        } else {
            $.post("/backend/security/hotel/resetPwd", {
                hotelId: id,
                password: $("#password").val(),
                mobile: $("#mobile").val()
            }, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                } else {
                    layer.msg('重置成功');
                }
            })
        }
        return false;
    });

    //删除民宿图片
    function deleteHotelPhoto(id) {
        $.post("/backend/security/hotelPhoto/del", {id: id}, function (res) {
            if (res.code < 0) {
                layer.msg(res.message);
            } else {
                $("#" + id + "").remove();
                layer.msg('删除成功');
            }
        });
    }

    //查询相关
    layui.form.on('submit(searchHomeBtn)', function (data) {
        hotelHomeTabIns.reload({
            where: data.field
        });
        return false;
    });

    //变更房间状态
    function changeStatus(id, status) {
        if (status == 0) {
            $.post('/backend/security/hotelHome/update', {id: id, status: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("下架成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        } else if (status = 1) {
            $.post('/backend/security/hotelHome/update', {id: id, status: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("上架成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        }
    }

    //变更推荐状态
    function changeRecommend(id, isRecommend) {
        if (isRecommend == 0) {
            $.post('/backend/security/hotelHome/update', {id: id, isRecommend: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("加入推荐成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        } else if (isRecommend = 1) {
            $.post('/backend/security/hotelHome/update', {id: id, isRecommend: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("取消推荐成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        }
    }

    //变更房间状态
    function changeOpen(id, isOpen) {
        if (isOpen == 0) {
            $.post('/backend/security/hotelHome/update', {id: id, isOpen: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("关闭房间成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        } else if (isOpen = 1) {
            $.post('/backend/security/hotelHome/update', {id: id, isOpen: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("开放房间成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        }
    }

    function changeTop(id, isTop) {
        if (isTop == 0) {
            $.post('/backend/security/hotelHome/update', {id: id, isTop: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("置顶房间成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        } else if (isTop = 1) {
            $.post('/backend/security/hotelHome/update', {id: id, isTop: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    } else {
                        layer.msg("取消置顶房间成功");
                        hotelHomeTabIns.reload();
                    }
                }
            )
        }
    }


    //初始加载
    $(function () {


        if (id != "") {

            //获取门店基础信息
            $.post('/backend/security/hotel/findHotelForm', {id: id}, function (result) {
                if (result.code < 0) {
                    layer.msg(res.message);
                } else {
                    $("#infoForm").loadData(result.body[0]);
                    checkInInstructionsEditor.txt.html(result.body[0].checkInInstructions);
                    playRaidersEditor.txt.html(result.body[0].playRaiders);
                    hotelInfoEditor.txt.html(result.body[0].hotelInfo);

                    //获取标签基础信息
                    $.post('/backend/security/sysDictionary/findList', function (res) {
                        if (res.code < 0) {
                            layer.msg(res.message);
                        } else {
                            var facilityDiv = "";
                            var dictEntry = res.body[0].dictEntry;
                            var dictName;
                            if (dictEntry == "basic_equipment") {
                                dictName = "基础设备";
                            }
                            if (dictEntry == "bathroom_equipment") {
                                dictName = "卫浴设备";
                            }
                            if (dictEntry == "household_equipment") {
                                dictName = "家用电器";
                            }
                            if (dictEntry == "general_equipment") {
                                dictName = "通用设施";
                            }
                            if (dictEntry == "service_equipment") {
                                dictName = "服务项目";
                            }
                            facilityDiv = facilityDiv + "<label class=\"layui-form-label\">" + dictName + "</label> <div class=\"layui-input-block " + dictEntry + "\">";
                            for (var i = 0; i < res.body.length; i++) {
                                if (dictEntry == res.body[i].dictEntry) {
                                    facilityDiv = facilityDiv + "<input type=\"checkbox\" name=\"" + res.body[i].dictEntry + "_" + i + "" + "\" title=\"" + res.body[i].dictPrompt + "\" value=\"" + res.body[i].dictImg + "\">";
                                } else {
                                    if (res.body[i].dictEntry == "basic_equipment") {
                                        dictName = "基础设备";
                                    }
                                    if (res.body[i].dictEntry == "bathroom_equipment") {
                                        dictName = "卫浴设备";
                                    }
                                    if (res.body[i].dictEntry == "household_equipment") {
                                        dictName = "家用电器";
                                    }
                                    if (res.body[i].dictEntry == "general_equipment") {
                                        dictName = "通用设施";
                                    }
                                    if (res.body[i].dictEntry == "service_equipment") {
                                        dictName = "服务项目";
                                    }
                                    facilityDiv = facilityDiv + "</div>";
                                    facilityDiv = facilityDiv + "<br/><label class=\"layui-form-label\">" + dictName + "</label> <div class=\"layui-input-block " + res.body[i].dictEntry + "\">";
                                    facilityDiv = facilityDiv + "<input type=\"checkbox\" name=\"" + res.body[i].dictEntry + "_" + i + "" + "\" title=\"" + res.body[i].dictPrompt + "\" value=\"" + res.body[i].dictImg + "\">";
                                }
                                dictEntry = res.body[i].dictEntry;
                            }
                            facilityDiv = facilityDiv + "</div>";
                            $("#facilityDiv").html(facilityDiv);
                            layui.form.render();


                            var facilityStr = result.body[0].hotelFacility;
                            if (facilityStr.basic.length > 0) {
                                for (var i = 0; i < facilityStr.basic.length; i++) {
                                    $.each($('.basic_equipment input:checkbox'), function () {
                                        if ($(this).attr("title") == facilityStr.basic[i].name)
                                            $(this).prop('checked', true);
                                    });
                                }
                            }
                            if (facilityStr.general.length > 0) {
                                for (var i = 0; i < facilityStr.general.length; i++) {
                                    $.each($('.general_equipment input:checkbox'), function () {
                                        if ($(this).attr("title") == facilityStr.general[i].name)
                                            $(this).prop('checked', true);
                                    });
                                }
                            }
                            if (facilityStr.bathroom.length > 0) {
                                for (var i = 0; i < facilityStr.bathroom.length; i++) {
                                    $.each($('.bathroom_equipment input:checkbox'), function () {
                                        if ($(this).attr("title") == facilityStr.bathroom[i].name)
                                            $(this).prop('checked', true);
                                    });
                                }
                            }
                            if (facilityStr.household.length > 0) {
                                for (var i = 0; i < facilityStr.household.length; i++) {
                                    $.each($('.household_equipment input:checkbox'), function () {
                                        if ($(this).attr("title") == facilityStr.household[i].name)
                                            $(this).prop('checked', true);
                                    });
                                }
                            }
                            if (facilityStr.service.length > 0) {
                                for (var i = 0; i < facilityStr.service.length; i++) {
                                    $.each($('.service_equipment input:checkbox'), function () {
                                        if ($(this).attr("title") == facilityStr.service[i].name)
                                            $(this).prop('checked', true);
                                    });
                                }
                            }
                            layui.form.render();
                        }
                    });

                    if (result.body[0].provinceCode) {
                        var index1 = $("#provinceCode option:checked").index() - 1;
                        citySelect(index1);
                        if (result.body[0].cityCode) {
                            $("#cityCode").val(result.body[0].cityCode);
                            var index2 = $("#cityCode option:checked").index() - 1;
                            distSelectFirst(index1, index2);
                            if (result.body[0].districtCode) {
                                $("#districtCode").val(result.body[0].districtCode);
                            }
                        }
                    }
                }
            });


            //获取门店照片
            $.post('/backend/security/hotelPhoto/find', {hotelId: id}, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                } else {
                    var photoDiv = "";
                    for (var i = 0; i < res.body.length; i++) {
                        photoDiv = photoDiv + "<div class=\"hotelImage-uploader\" id=\"" + res.body[i].id + "\">\n" +
                            "                <div class=\"image-preview\">\n" +
                            "                    <div class=\"image\">\n" +
                            "                        <img src=\"" + res.body[i].url + "\"  id=\"img\">\n" +
                            "                        <span class=\"image-browse\" onclick=\"deleteHotelPhoto('" + res.body[i].id + "')\"><strong>删除图片</strong><span\n" +
                            "                                class=\"progress\"><span class=\"progress-bar\"></span></span></span>\n" +
                            "                    </div>\n" +
                            "                </div>\n" +
                            "            </div><br/>"
                    }
                    $("#photoList").html(photoDiv);
                }
            });

            //获取民宿房间
            hotelHomeTabIns = createTable({
                url: '/backend/security/hotelHome/list?hotelId=' + $("#id").val(),
                id: "hotelHomeGrid",
                elem: '#hotelHomeGrid',
                cols: [[{field: 'id', title: '编号', width: 80},
                    {field: 'homeName', title: '房间名称', width: 180}, {
                        field: 'homeInfo',
                        title: '房间介绍',
                        width: 200
                    }, {
                        field: 'status',
                        title: '状态',
                        width: 80, templet: '#statusTpl'
                    }, {
                        field: 'isRecommend',
                        title: '是否推荐',
                        width: 80, templet: '#recommendTpl'
                    }, {
                        field: 'isOpen',
                        title: '是否开放',
                        width: 80, templet: '#openTpl'
                    }, {
                        field: 'isTop',
                        title: '是否置顶',
                        width: 80, templet: '#topTpl'
                    }, {
                        field: 'openStart',
                        title: '关房起始时间',
                        width: 150
                    }, {
                        field: 'openEnd',
                        title: '关房結束时间',
                        width: 150
                    }, {
                        fixed: 'right',
                        title: '操作',
                        width: 400,
                        align: 'center',
                        toolbar: '#homeOpbar'
                    }
                ]], height: ''
            });

            //数据表格工具条
            layui.table.on('tool(hotelHomeGrid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                if (layEvent === 'change') { //
                    layer.confirm('确认变更房间状态?', function (index) {
                        changeStatus(data.id, data.status);
                    });
                } else if (layEvent === 'edit') { //编辑
                    openDialog({
                        url: "/backend/security/hotelHome/detail?id=" + data.id,
                        area: ["80%", "95%"],
                        btn: ["确认", "取消"]
                    });
                } else if (layEvent === 'cancelRecommend') { //编辑
                    layer.confirm('确认将房间取消推荐?', function (index) {
                        changeRecommend(data.id, data.isRecommend);
                    });
                } else if (layEvent === 'inRecommend') { //编辑
                    layer.confirm('确认将房间加入推荐?', function (index) {
                        changeRecommend(data.id, data.isRecommend);
                    });
                } else if (layEvent === 'openHome') { //编辑
                    layer.confirm('确认将房间开放?', function (index) {
                        changeOpen(data.id, data.isOpen);
                    });
                } else if (layEvent === 'closeHome') { //编辑
                    layer.confirm('确认将房间关闭?', function (index) {
                        changeOpen(data.id, data.isOpen);
                    });
                } else if (layEvent === 'cancelTop') { //编辑
                    layer.confirm('确认将房间取消置顶?', function (index) {
                        changeTop(data.id, data.isTop);
                    });
                } else if (layEvent === 'inTop') { //编辑
                    layer.confirm('确认将房间首页置顶?', function (index) {
                        changeTop(data.id, data.isTop);
                    });
                }
            });
            layui.form.render();
        } else {
            $("#hotelPhotoLi").remove();
            $("#hotelHomeLi").remove();
            $("#checkInInstructionsLi").remove();
            $("#playRaidersLi").remove();
            $("#hotelSetLi").remove();

            $("#resetDiv").remove();
            $("#resetBtn").remove();
            //获取标签基础信息
            $.post('/backend/security/sysDictionary/findList', function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                } else {
                    var facilityDiv = "";
                    var dictEntry = res.body[0].dictEntry;
                    var dictName;
                    if (dictEntry == "basic_equipment") {
                        dictName = "基础设备";
                    }
                    if (dictEntry == "bathroom_equipment") {
                        dictName = "卫浴设备";
                    }
                    if (dictEntry == "household_equipment") {
                        dictName = "家用电器";
                    }
                    if (dictEntry == "general_equipment") {
                        dictName = "通用设施";
                    }
                    if (dictEntry == "service_equipment") {
                        dictName = "服务项目";
                    }
                    facilityDiv = facilityDiv + "<label class=\"layui-form-label\">" + dictName + "</label> <div class=\"layui-input-block " + dictEntry + "\">";
                    for (var i = 0; i < res.body.length; i++) {
                        if (dictEntry == res.body[i].dictEntry) {
                            facilityDiv = facilityDiv + "<input type=\"checkbox\" name=\"" + res.body[i].dictEntry + "_" + i + "" + "\" title=\"" + res.body[i].dictPrompt + "\" value=\"" + res.body[i].dictImg + "\">";
                        } else {
                            if (res.body[i].dictEntry == "basic_equipment") {
                                dictName = "基础设备";
                            }
                            if (res.body[i].dictEntry == "bathroom_equipment") {
                                dictName = "卫浴设备";
                            }
                            if (res.body[i].dictEntry == "household_equipment") {
                                dictName = "家用电器";
                            }
                            if (res.body[i].dictEntry == "general_equipment") {
                                dictName = "通用设施";
                            }
                            if (res.body[i].dictEntry == "service_equipment") {
                                dictName = "服务项目";
                            }
                            facilityDiv = facilityDiv + "</div>";
                            facilityDiv = facilityDiv + "<br/><label class=\"layui-form-label\">" + dictName + "</label> <div class=\"layui-input-block " + res.body[i].dictEntry + "\">";
                            facilityDiv = facilityDiv + "<input type=\"checkbox\" name=\"" + res.body[i].dictEntry + "_" + i + "" + "\" title=\"" + res.body[i].dictPrompt + "\" value=\"" + res.body[i].dictImg + "\">";
                        }
                        dictEntry = res.body[i].dictEntry;
                    }
                    facilityDiv = facilityDiv + "</div>";
                    $("#facilityDiv").html(facilityDiv);
                    layui.form.render();
                }
            });
        }

    });

</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status ===1){ }}
    <span style="color: #FF0000;">下架</span>
    {{#  } else { }}
    <span style="color: green;">上架</span>
    {{#  } }}
</script>
<script type="text/html" id="recommendTpl">
    {{#  if(d.isRecommend ===1){ }}
    <span style="color: green;">推荐中</span>
    {{#  } else { }}
    <span>不推荐</span>
    {{#  } }}
</script>
<script type="text/html" id="openTpl">
    {{#  if(d.isOpen ===0){ }}
    <span style="color: green;">开放中</span>
    {{#  } else { }}
    <span style="color: #FF0000;">关闭中</span>
    {{#  } }}
</script>
<script type="text/html" id="topTpl">
    {{#  if(d.isTop ===0){ }}
    <span style="color: green;">未置顶</span>
    {{#  } else { }}
    <span style="color: #FF0000;">已置顶</span>
    {{#  } }}
</script>
<script type="text/html" id="homeOpbar">
    <a class="layui-btn layui-btn-xs opbarEdit" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="change">变更状态</a>
    {{#  if(d.isRecommend ===1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="cancelRecommend">取消推荐</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="inRecommend">加入推荐</a>
    {{#  } }}
    {{#  if(d.isOpen ===1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="openHome">开放房间</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="closeHome">关闭房间</a>
    {{#  } }}
    {{#  if(d.isTop ===1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="cancelTop">取消置顶</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="inTop">加入置顶</a>
    {{#  } }}
</script>
</body>
</html>
